// 主体的轮播图
var mySwiper = new Swiper(".swiper", {
  loop: true, // 循环模式选项

  // 如果需要分页器
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },

  // 如果需要前进后退按钮
  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },
  // 自动播放
  autoplay: {
    delay: 3000, //间隔时间
    stopOnLastSlide: false, //到最后一个是否停止
    disableOnInteraction: false, //用户操作了 是否停止
  },
});
$(".swiper").addEventListener("mouseover", function () {
  mySwiper.autoplay.stop();
});
$(".swiper").addEventListener("mouseout", function () {
  mySwiper.autoplay.start();
});

/* api分类
$a(".api-list li").forEach(function (li) {
  li.addEventListener("mouseover", function () {
    li.children[0].style.display = "none";
    li.children[1].style.display = "inline-block";
  });

  li.addEventListener("mouseout", function () {
    li.children[0].style.display = "inline-block";
    li.children[1].style.display = "none";
  });
}); */
// 保存图片路径
let file = "";
$a(".api-list li").forEach(function (li) {
  li.addEventListener("mouseover", function () {
    let path = this.children[0].src;
    let index1 = path.lastIndexOf("/");
    let index2 = path.lastIndexOf(".");
    file = path.substring(index1 + 1, index2);
    this.children[0].src = `../../assets/imgs/${file}-c.svg`;
  });

  li.addEventListener("mouseout", function () {
    this.children[0].src = `../../assets/imgs/${file}.svg`;
  });
});

// 银行轮播
let index = 0;
// window.setInterval(function () {
//   ++index;
//   if (index === $a(".bank-content>div").length) {
//     index = 0;
//   }
//   if (index == 0) {
//     $a(".bank-content>div")[length - 1].classList.remove("active");
//   } else {
//     $a(".bank-content>div")[index - 1].classList.remove("active");
//   }
//   $a(".bank-content>div")[index].classList.add("active");
// }, 3000);
let bankList = document.querySelectorAll(".bank-content>div");
window.setInterval(function () {
  ++index;
  if (index === bankList.length) {
    index = 0;
  }
  if (index === 0) {
    bankList[bankList.length - 1].classList.remove("active");
  } else {
    bankList[index - 1].classList.remove("active");
  }
  bankList[index].classList.add("active");
}, 3000);

// 回到顶部
$(".toTop").addEventListener("click", function () {
  window.scrollTo({
    top: 0,
    behavior: "smooth",
  });
});
window.addEventListener("scroll", function () {
  if (window.scrollY > 400) {
    $(".toTop").style.display = "block";
  } else {
    $(".toTop").style.display = "none";
  }
});
